package cn.iocoder.yudao.module.xiaoBizHandler.service.tbGenInstance;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.xiaoBizHandler.controller.admin.tbGenInstance.vo.*;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.tbGenInstance.XTbGenInstanceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.xiaoBizHandler.convert.tbGenInstance.XTbGenInstanceConvert;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.mysql.tbGenInstance.XTbGenInstanceMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.xiaoBizHandler.enums.ErrorCodeConstants.*;

/**
 * 代码生成示例 Service 实现类
 *
 * @author xiaosy
 */
@Service
@Validated
public class XTbGenInstanceServiceImpl implements XTbGenInstanceService {

    @Resource
    private XTbGenInstanceMapper xTbGenInstanceMapper;

    @Override
    public String createXTbGenInstance(XTbGenInstanceCreateReqVO createReqVO) {
        // 插入
        XTbGenInstanceDO xTbGenInstance = XTbGenInstanceConvert.INSTANCE.convert(createReqVO);
        xTbGenInstanceMapper.insert(xTbGenInstance);
        // 返回
        return xTbGenInstance.getId();
    }

    @Override
    public void updateXTbGenInstance(XTbGenInstanceUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateXTbGenInstanceExists(updateReqVO.getId());
        // 更新
        XTbGenInstanceDO updateObj = XTbGenInstanceConvert.INSTANCE.convert(updateReqVO);
        xTbGenInstanceMapper.updateById(updateObj);
    }

    @Override
    public void deleteXTbGenInstance(String id) {
        // 校验存在
        this.validateXTbGenInstanceExists(id);
        // 删除
        xTbGenInstanceMapper.deleteById(id);
    }

    private void validateXTbGenInstanceExists(String id) {
        if (xTbGenInstanceMapper.selectById(id) == null) {
            throw exception(XT_B_GEN_INSTANCE_NOT_EXISTS);
        }
    }

    @Override
    public XTbGenInstanceDO getXTbGenInstance(String id) {
        return xTbGenInstanceMapper.selectById(id);
    }

    @Override
    public List<XTbGenInstanceDO> getXTbGenInstanceList(Collection<String> ids) {
        return xTbGenInstanceMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<XTbGenInstanceDO> getXTbGenInstancePage(XTbGenInstancePageReqVO pageReqVO) {
        return xTbGenInstanceMapper.selectPage(pageReqVO);
    }

    @Override
    public List<XTbGenInstanceDO> getXTbGenInstanceList(XTbGenInstanceExportReqVO exportReqVO) {
        return xTbGenInstanceMapper.selectList(exportReqVO);
    }

}

